package com.zsy.controller;

import com.zsy.entity.PurchaseRequirements;
import com.zsy.service.IPurchaseRequirementsService;
import com.zsy.utils.PageBean;
import com.zsy.utils.Result;
import com.zsy.utils.Result02;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 采购需求的控制层
 * @Author: WeilinZhang
 * @Date: 2020/12/4 16:38
 *
 */


// 集成了ResponseBody；当前的方法返回的页面是纯文本
@RestController
// 当前类中的所有请求路径都加上该路径
@RequestMapping("/PurchaseRequirements")
// 验证请求参数
@Validated
// 跨域问题解决方案
@CrossOrigin
public class PurchaseRequirementsController {

    //注入service
    @Autowired
    private IPurchaseRequirementsService PRSI;

    @PostMapping("/login")
    public String login(String user){
        System.out.println(user);
        return "login";
    }

    /**
     * 采购需求的分页加条件查询
     * @param pageNum 当前页
     * @param pageSize 每页显示条数
     * @param relatedTo 关联项目名称
     * @param initiatingDepartment 发起部门
     * @param itemName 物品名称
     * @return PageBean类
     */
    @GetMapping("/PRlist")
    public Result02<PageBean<PurchaseRequirements>> list(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) String relatedTo,
            @RequestParam(required = false) String initiatingDepartment,
            @RequestParam(required = false) String itemName) {
        PageBean<PurchaseRequirements> list = PRSI.list(pageNum, pageSize, relatedTo, initiatingDepartment, itemName);
        return Result02.success(list);
    }

    /**
     * 根据id删除
     * @param id
     * @return Result类
     */
    @PutMapping("/delete")
    public Result delete(Integer id) {
        return PRSI.deleteById(id);
    }

    /**
     * 新增
     * @param PR PurchaseRequirementsl类
     * @return Result类
     */
    @PutMapping("/updata")
    public Result updata(@RequestBody @Validated PurchaseRequirements PR) {
        return PRSI.update(PR);
    }


}
